
import pagination from '@/views/pagination'  //分页组件
import router from '@/router'
import dialogForm from './edit'
import agentHttp from '@/utils/agentHttp.js'
export default {
  name: 'webContract',
  components:{dialogForm,pagination},
  created(){
    this.getContractinfoList(); 
   // this.openContract();
  },
  data() {
  	return {

        //表格字段
        tableData:{},

        //弹窗状态值
        isAdd:{bool:true},
        dialogFormVisible: {bool:false},
        query:{index:""},
        formLabelWidth:'120px',

        searchForm:{
          endDate:"",
          status:"",
          startDate:"",
          orderNumber:"",
          dealerName:"",
          status:"",
          carBrand:"",     

        },
        statusFnished :"FINISHED",
        userType: "",
        rowData:{},
        lianshangcheNumber:0,
        startDateOpt: {
          disabledDate(time) {
            return time.getTime() > Date.now() 
          }
        },
        endDateOpt:{
            disabledDate:(time)=>{
              return  time.getTime()< new Date(this.searchForm.startDate).getTime()- 8.64e7;
            }
        },
        resetFormStatus:false
        
        
  	}
  }, 
  methods: {
    /*搜索按钮方法*/
    //重置
    resetSearchForm(formName) {
        this.resetFormStatus=true;
        this.tableData.page=1;
        this.tableData.rows=10;
        this.$refs[formName].resetFields();
        this.$nextTick(_ =>{
          this.resetFormStatus=false;
          this.getContractinfoList();
        })
    },
    /*表格操作按钮*/
    getContractinfoList(){  
      if(!this.resetFormStatus){ 
        var params=this.searchForm||{};    
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;  
        agentHttp.post('adminApi/admin/contractinfo/get_contractinfo_list',params ).then((data)=>{
              if(data.success){ 
                this.tableData = data.data.contractList; 
                this.userType = data.data.userType; 
              } 
        })
      }
    },
    handleDown(contractId){ 
      if(contractId === null || contractId === ""){
        this.$message.warning('合同ID为空...'); 
        return;
      }
     
      var newTab=window.open('about:loding....');
      agentHttp.get('adminApi/admin/contractinfo/download_contract/' +  contractId).then((data)=>{   
                this.openWindow(newTab,data);
      }) 
    },openContract( id){
       var newTab1=window.open('about:loding....');
       agentHttp.get('adminApi/admin/contractinfo/view_yht_contract/' +  id).then((data)=>{
           if(data.success){
              this.openWindow(newTab1,data.data);
           }
           else {
              this.$message.warning(data.err); 
              newTab1.close();
           }
       })   
    },
    openWindow(obj,url){
        obj.location.href= url; 
    },
    changeQuey(){
      this.tableData.page=1;
      this.getContractinfoList();
    },
    startDateGet(date){
      this.searchForm.startDate = date;
      this.changeQuey();
    },
    endDateGet(date){
      this.searchForm.endDate = date;
      this.changeQuey();
    },
    userStatus(user,userStatus){
      var flag = null;
      if(user != "" && userStatus === 1){
        flag = 1;
      }
      else if(user != "" && userStatus === 0){
        flag = 2;
      }
      return flag; 
    }
    //
    /*send(){
      eventIsAdd.$emit('eventIsAdd', this.isAdd);
    }*/
  }
}
